from likeshop_api_project.api.login_api import login_model
from likeshop_api_project.base.mybase import Tools
from likeshop_api_project.api.get_user_address import get_user_address_model
import random

# 设置默认地址
class set_default_address_model(Tools):
    path = '/api/user_address/setdefault'

    # def get_random_address_id(self, hd):
    #     address_lists = get_user_address_model(self.huihua).get_user_address_action(hd)
    #     print(address_lists)
    #     return random.choice(address_lists['data'])['id']

    def set_default_address_action(self, id, hd):
        set_default_address_data = {
            "id": id
        }
        set_default_address = self.huihua.post(url=self.hosturl+self.path, data=set_default_address_data, headers=hd)
        return set_default_address.json()


if __name__ == '__main__':
    import requests

    s = requests.session()
    reg = login_model(huihua=s)
    msg = reg.login_action(account="13356786546", password="rr98765", client=2)
    get_token = msg["data"]["token"]
    hd = {"token": get_token}

    set_default_address = set_default_address_model(huihua=s)
    # random_id = get_an_address.get_random_address_id(hd=hd)
    msg = set_default_address.set_default_address_action(id=831, hd=hd)
    print(msg)
